package org.iabako.shared.iservice.user;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.iabako.shared.entity.business.ClientCommunication;
import org.iabako.shared.entity.business.Payment;
import org.iabako.shared.entity.business.Sale;
import org.iabako.shared.entity.enumeration.IabakoPackage;
import org.iabako.shared.entity.user.Enterprise;
import org.iabako.shared.entity.user.User;
import org.iabako.shared.entity.user.UserPayPalToken;
import org.iabako.shared.entity.user.UserPayPalTokenUser;
import org.iabako.shared.iservice.generic.CRUDServiceAsync;
import org.iabako.shared.iservice.generic.SearchServiceAsync;

import java.util.List;

/**
 * Created by jose on 24/09/14.
 */
public interface UserServiceAsync extends CRUDServiceAsync, SearchServiceAsync {

    void getUserByEmail(String username, AsyncCallback<User> async);

    void save(User entity, AsyncCallback<User> async);

    void getUserPayPalTokenPayedOrToVerify(String iabakoTxId, AsyncCallback<UserPayPalToken> async);

    void setUserPayPalTokenPayed(String iabakoTxId, String payPalPayerEmail, String payPalResponse, AsyncCallback<Void> async);

    void setUserPayPalTokenToVerify(String transactionId, String payPalResponse, AsyncCallback<Void> async);

    void setUserPayPalTokenCanceled(String transactionId, String payPalResponse, AsyncCallback<Void> async);

    void calculateUserCredit(boolean isUpgrade, User user, IabakoPackage iabakoPackage, int quantity, AsyncCallback<Void> async);

    void getUsersBySessionEnterprise(AsyncCallback<List<User>> async);

    void savePayPalToken(UserPayPalToken payPalToken, List<UserPayPalTokenUser> userTokens, AsyncCallback<String> async);

    void addInvoiceReceiptToEnterpriseBalance(Sale sale, Payment payment, AsyncCallback<Void> async);

    void addCommunicationToEnterpriseBalance(ClientCommunication clientCommunication, AsyncCallback<Void> async);

    void reloadNotifications(Enterprise enterprise, boolean forced, AsyncCallback<Void> async);

    void getPrincipalUser(AsyncCallback<User> async);

    public static final class Util {
        private static UserServiceAsync instance;

        public static final UserServiceAsync getInstance() {
            if (instance == null) {
                instance = GWT.create(UserService.class);
            }
            return instance;
        }
    }
}
